package controller

import (
	"hft/Database/admin"
	"hft/Http/Models/request"
	"hft/Http/Models/response"
	services "hft/Http/Services"
	utils "hft/Http/Utils"
	"hft/e"

	"github.com/gin-gonic/gin"
)

type CountrySetting struct{}

func (*CountrySetting) Edit(c *gin.Context) {

	var data *admin.CountrySetting

	c.ShouldBindJSON(&data)

	err := services.CountrySettingService.Edit(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

func (*CountrySetting) Info(c *gin.Context) {

	data, err := services.CountrySettingService.Info()

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(data, c)
}

func (*CountrySetting) EditAssist(c *gin.Context) {

	var data *admin.Assist

	c.ShouldBindJSON(&data)

	err := services.CountrySettingService.EditAssist(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

func (*CountrySetting) EditPrivate(c *gin.Context) {

	var data *admin.Private

	c.ShouldBindJSON(&data)

	err := services.CountrySettingService.EditPrivate(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

func (*CountrySetting) GetAssist(c *gin.Context) {

	data, err := services.CountrySettingService.GetAssist()

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(data, c)
}

func (*CountrySetting) GetPrivate(c *gin.Context) {

	data, err := services.CountrySettingService.GetPrivate()

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(data, c)
}

func (*CountrySetting) CreateOri(c *gin.Context) {

	var data *admin.Origin

	c.ShouldBindJSON(&data)

	err := services.CountrySettingService.CreateOri(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

func (*CountrySetting) EditOri(c *gin.Context) {

	var data *admin.Origin

	c.ShouldBindJSON(&data)

	err := services.CountrySettingService.UpdateOri(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

func (*CountrySetting) DeleteOri(c *gin.Context) {

	var IDS *request.IDS

	c.ShouldBindJSON(&IDS)

	err := services.CountrySettingService.DeleteOri(IDS.IDS)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

func (*CountrySetting) GetOriList(c *gin.Context) {

	var list = make([]*response.OriginItem, 0)
	list = append(list, &response.OriginItem{Port: e.PC.Port, Name: e.PC.Name})
	list = append(list, &response.OriginItem{Port: e.H5.Port, Name: e.H5.Name})
	list = append(list, &response.OriginItem{Port: e.WE_APP.Port, Name: e.WE_APP.Name})
	list = append(list, &response.OriginItem{Port: e.BAIDU_APP.Port, Name: e.BAIDU_APP.Name})
	list = append(list, &response.OriginItem{Port: e.TITOK_APP.Port, Name: e.TITOK_APP.Name})
	list = append(list, &response.OriginItem{Port: e.PHONE_400.Port, Name: e.PHONE_400.Name})
	list = append(list, &response.OriginItem{Port: e.AUTO_RECORD.Port, Name: e.AUTO_RECORD.Name})
	utils.OkWithData(list, c)
}

var CountrySettingController = new(CountrySetting)
